<template>
    <div class="content-box">
      <div ref="searchBox" class="search-box flex" v-show="showSearch">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          label-width="100px"
        >
         <el-form-item label="产品名称"  prop="productName">
           <el-input
             v-model="queryParams.productName"
             placeholder="请输入"
             style="width: 240px; margin-right: 20px"
             clearable
           ></el-input>
         </el-form-item>
          <el-form-item label="关联公司" prop="companyIds">
            <el-select
              v-model="queryParams.companyIds"
              multiple
              collapse-tags
              clearable
              filterable
              placeholder="请选择"
              style="width: 240px; margin-right: 20px"
            >
              <el-option
                v-for="(item, index) in downCompanyList"
                :key="index"
                :label="item.companyName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="渠道产品" prop="productIds">
            <el-select
              v-model="queryParams.productIds"
              multiple
              collapse-tags
              clearable
              filterable
              placeholder="请选择"
              style="width: 240px; margin-right: 20px"
            >
              <el-option
                v-for="(item, index) in upChannelList"
                :key="index"
                :label="item.productName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="管理人" prop="manageUserIds">
            <el-select
              v-model="queryParams.manageUserIds"
              multiple
              collapse-tags
              clearable
              filterable
              placeholder="请选择管理人"
              style="width: 240px; margin-right: 20px"
            >
              <el-option
                v-for="(item, index) in manageOptionList"
                :key="index"
                :label="item.userName"
                :value="item.userId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="在线状态" prop="status">
            <el-select
              v-model="queryParams.status"
              clearable
              filterable
              placeholder="请选择"
              style="width: 240px; margin-right: 20px"
            >
              <el-option
                v-for="(item, index) in statusOption"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="查询时间" prop="dateRange">
            <el-date-picker
              :style="{width: device === 'mobile'? '280px' :'355px', marginRight: '20px'}"
              clearable
              v-model="dateRange"
              type="datetimerange"
              range-separator="至"
              value-format="yyyy-MM-dd HH:mm:ss"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              plain
              >查询</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
            <el-button
              type="primary"
              size="mini"
              v-hasPermi="['business:upPickManagement:add']"
              @click="handelDialog('添加', null)"
              >添加贷超</el-button
            >
          </el-form-item>
        </el-form>
      </div>
  
      <div class="table-box">
        <el-row :gutter="10" class="mb8">
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="handleQuery"
            :columns="columnsList"
          ></right-toolbar>
        </el-row>
        <el-table
          v-sticky-header
          ref="table"
          v-loading="loading"
          :data="dataList"
        >
          <template v-for="(item,index) in columns.slice(0, columns.length - 1)">
            <el-table-column
              :key="index"
              :label="item.label"
              :prop="item.prop"
              :width="getColumnWidth(index)"
              align="center"
              :fixed="item.fixed"
              :sortable="item.sortable ? item.sortable : false"
              :show-overflow-tooltip="item.showTooltip"
              v-if="item.visible"
            >
              <template slot-scope="scope">
               <!--上下线状态单独处理 -->
              <div v-if="item.prop === 'status'" @click="showOrOffPopo(scope.row)">
                <el-popover
                  placement="top"
                  trigger="click"
                  :value ="rowIndex === scope.row.id"
                  title="上下线状态操作"
                  >
                  <el-form >
                    <el-form-item style="margin-bottom: 0;">
                      <el-radio-group v-removeAriaHidden v-model="upAndDownLinesStates" >
                        <el-radio 
                         v-for="(item,index) in statusOption" 
                        :key="index" :label="item.value">{{ item.label }}
                      </el-radio>
                     </el-radio-group>
                    </el-form-item>
                    <el-form-item style="display: flex;justify-content: center;margin-bottom: 8px;">
                      <el-button type="primary" @click="clickSubmitOnOrOff(scope.row)">提交</el-button>
                      <el-button @click="clickCancelOnOrOff(scope.row)">取消</el-button>
                    </el-form-item>
                  </el-form>
                  <el-button 
                     slot="reference"
                     :type="statusColor(scope.row[item.prop])" 
                     size="mini" 
                   >{{ ArrayFormatObj(statusOption)[scope.row[item.prop]]}}</el-button>
                </el-popover> 
              </div>
              <!-- 产品logo地址处理 -->
              <div v-else-if="item.prop === 'logoUrl'">
                 <el-image
                   v-if="scope.row[item.prop]"
                   style="width: 100px; height: 100px;border-radius: 6px;"
                   :src="scope.row[item.prop]"
                   :preview-src-list="[scope.row[item.prop]]"
                   ></el-image>
              </div>
              <!-- 是否企微产品处理 -->
              <div v-else-if="item.prop === 'isWeChat'">
                 {{ ArrayFormatObj(isWeChatOption)[scope.row[item.prop]] || '-'}}
              </div>
              <span v-else>
                {{  scope.row[item.prop] }}
              </span>
              </template>
            </el-table-column>
          </template>
          <el-table-column
            fixed="right"
            :prop="columns[columns.length - 1].prop"
            :label="columns[columns.length - 1].label"
            align="center"
            :width="getColumnWidth(columns.length - 1)"
            v-if="columns[columns.length - 1].visible"
          >
            <template slot-scope="scope">
              <div class="flex-center flex">
                <!-- <el-button
                  type="text"
                  v-hasPermi="['business:upPickManagement:query']"
                  @click="handelDialog('查看', scope.row)"
                  >查看</el-button
                 > -->
                <el-button
                  type="text"
                  v-hasPermi="['business:upPickManagement:edit']"
                  @click="handelDialog('编辑', scope.row)"
                  >编辑</el-button
                >
                <el-popconfirm
                  title="确定要删除该贷超吗？"
                  style="margin-left: 10px"
                  @cancel="hanCancelDel"
                  @confirm="handelDel(scope.row)"
                >
                  <el-button
                    slot="reference"
                    type="text"
                    v-hasPermi="['business:upPickManagement:remove']"
                    ><span style="color: #ff116e">删除</span></el-button
                  >
                </el-popconfirm>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 使用分页插件 -->
        <pagination
          v-show="total > 0"
          :total="total"
          :page-sizes="[10, 50, 100, 200, 500]"
          :page.sync="queryParams.pageIndex"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
      <!-- 新增/编辑/查看 对话框 -->
      <el-dialog
        :title="title"
        width="800px"
        :visible.sync="dialogShow"
        :before-close="handleClose"
      >
        <el-form :model="form" :rules="rules" label-width="140px" ref="formRef">
          <el-form-item label="关联公司" prop="companyId">
             <el-select
               v-if="!form.id"
               v-model="form.companyId"
               clearable
               filterable
               placeholder="请选择"
               style="width: 100%"
             >
               <el-option
                 v-for="(item, index) in downCompanyList"
                 :key="index"
                 :label="item.companyName"
                 :value="item.id"
               ></el-option>
             </el-select>
             <el-input
              v-else
              v-model="form.companyName"
              style="width: 100%"
              placeholder="请输入关联公司"
              clearable
              :disabled="!!form.id"
            />
          </el-form-item>
          <el-form-item label="产品名称" prop="productName">
            <el-input
              v-model="form.productName"
              style="width: 100%"
              placeholder="请输入产品名称"
              clearable
              :disabled="viewsOptionState"
            />
          </el-form-item>
          <el-form-item label="贷超模式" prop="pickType">
            <el-select
              v-model="form.pickType"
              clearable
              filterable
              placeholder="请选择"
              style="width: 100%"
              :disabled="viewsOptionState"
            >
              <el-option
                v-for="(item, index) in pickTypeOption"
                :key="index"
                :label="item.value"
                :value="item.key"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item 
          :key="form.pickType"
          label="跳转链接" :prop="form.pickType == 2 ?'productUrl':''"
          v-if="[2].includes(form.pickType)"
          >
            <el-input
              v-model="form.productUrl"
              style="width: 100%"
              placeholder="请输入跳转链接"
              clearable
              :disabled="viewsOptionState"
            />
          </el-form-item>
          <el-form-item label="产品简称" prop="simpleName">
            <el-input
              v-model="form.simpleName"
              style="width: 100%"
              placeholder="请输入产品简称"
              clearable
              :disabled="viewsOptionState"
            />
          </el-form-item>
          <el-form-item label="产品logo" prop="logoUrl" style="width: 50%;margin-right: 35px;">
            <ImageUpload
             :value="form.logoUrl"
             :isShowTip="false"
             :limit="1"
             @input="fileUploadFunction"
             :disabled="viewsOptionState"
            >
            </ImageUpload>
          </el-form-item>
          <el-form-item label="每日限量" prop="orderNum">
              <el-input-number 
                v-model="form.orderNum" 
                controls-position="right" 
                placeholder="请输入"
                :min="0" 
                style="width: 100%;"
                :disabled="viewsOptionState"
              >
              </el-input-number>
          </el-form-item>
          <el-form-item label="计费模式" prop="feeType">
            <el-select
              v-model="form.feeType"
              clearable
              filterable
              placeholder="请选择"
              style="width: 100%"
              :disabled="viewsOptionState"
            >
              <el-option
                v-for="(item, index) in feeTypeOption"
                :key="index"
                :label="item.value"
                :value="item.key"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单价" prop="priceMoney">
              <el-input-number 
                v-model="form.priceMoney" 
                controls-position="right" 
                placeholder="请输入"
                :min="0" 
                style="width: 100%;"
                :disabled="viewsOptionState"
              >
              </el-input-number>
          </el-form-item>
          <el-form-item 
          label="超时时间（毫秒）" prop="timeOut"
          v-if="![2].includes(form.pickType)"
          >
              <el-input-number 
                v-model="form.timeOut" 
                controls-position="right" 
                placeholder="请输入"
                :min="0" 
                style="width: 100%;"
                :disabled="viewsOptionState"
              >
              </el-input-number>
          </el-form-item>
          <el-form-item label="渠道限制" prop="isChannel">
            <el-select
              v-model="form.isChannel"
              clearable
              filterable
              placeholder="请选择"
              style="width: 100%"
              :disabled="viewsOptionState"
            >
              <el-option
                v-for="(item, index) in isChannelOption"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item 
          label="限制渠道集合" prop="channelIds"
          v-if="[1,2].includes(form.isChannel)"
          >
              <el-select
               v-model="form.channelIds"
               multiple
               clearable
               filterable
               placeholder="请选择"
               style="width: 100%"
               :disabled="viewsOptionState"
              >
                <el-option
                 v-for="(item, index) in channelIdsOption"
                 :key="index"
                 :label="item.simpleName"
                 :value="item.id"
                 ></el-option>
              </el-select>
           </el-form-item>
           <el-form-item label="城市限制" prop="isCity">
              <el-radio-group
               v-removeAriaHidden 
               v-model="form.isCity" 
               style="width: 100%"
               :disabled="viewsOptionState"
               >
                <el-radio 
                 v-for="(item,index) in isCityOption" 
                 :key="index" :label="item.value">{{ item.label }}
                </el-radio>
              </el-radio-group>
           </el-form-item>
           <el-form-item 
            v-if="form.isCity"
            label="选择城市" prop="cityCode">
               <el-cascader
                 ref="cascaderRef"
                 clearable
                 filterable
                 v-model="form.cityCode"
                 v-removeAriaHidden
                 @change="cascaderChangeFun"
                 :options="areaList"
                 :props="{
                   value: 'code',
                   label: 'name',
                   children: 'list',
                   emitPath: false,
                   checkStrictly: false,
                   multiple:true
                 }"
                 :disabled="viewsOptionState"
                 placeholder="请选择省市"
                 style="width: 100%"
               ></el-cascader>
           </el-form-item>
          
          <el-form-item label="企微产品" prop="isWeChat">
            <el-select
              v-model="form.isWeChat"
              clearable
              filterable
              placeholder="请选择"
              style="width: 100%"
              :disabled="viewsOptionState"
            >
              <el-option
                v-for="(item, index) in isWeChatOption"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="采量时间类型" prop="isZone">
            <el-select
              v-model="form.isZone"
              clearable
              filterable
              placeholder="请选择"
              style="width: 100%"
              :disabled="viewsOptionState"
            >
              <el-option
                v-for="(item, index) in isZoneOption"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
         
          <el-form-item label="采量时间范围" prop="pickDateRange">
            <el-time-picker
               format="HH:mm"
               style="width: 50%"
               v-model="form.startTime"
               placeholder="请选择开始时间"
               :disabled="viewsOptionState"
            >
            </el-time-picker>
            <el-time-picker
               format="HH:mm"
               style="width: 50%"
               v-model="form.endTime"
               placeholder="请选择结束时间"
               :disabled="viewsOptionState"
            >
            </el-time-picker>
          </el-form-item>
          <el-form-item label="轮转数(1~5)" prop="plusNum">
              <el-input-number 
                v-model="form.plusNum" 
                controls-position="right" 
                placeholder="请输入"
                :min="1" 
                :max="5"
                style="width: 100%;"
                :precision="0"
                :disabled="viewsOptionState"
              >
              </el-input-number>
          </el-form-item>
          <el-form-item label="在线状态" prop="status">
            <el-select
              v-model="form.status"
              clearable
              filterable
              placeholder="请选择"
              style="width: 100%"
              :disabled="viewsOptionState"
            >
              <el-option
                v-for="(item, index) in statusOption"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="展示额度" prop="quota">
              <el-input
               v-model="form.quota"
               placeholder="请输入"
               clearable
               style="width: 100%;"
               :disabled="viewsOptionState"
              ></el-input>
          </el-form-item>
          <el-form-item label="年化率" prop="yearRate">
              <el-input
               v-model="form.yearRate"
               placeholder="请输入"
               clearable
               style="width: 100%;"
               :disabled="viewsOptionState"
              ></el-input>
          </el-form-item>
          <el-form-item label="贷款期限" prop="termNum">
              <el-input
               v-model="form.termNum"
               clearable
               style="width: 100%;"
               placeholder="请输入贷款期限(例如：3~36个月)"
               :disabled="viewsOptionState"
              ></el-input>
          </el-form-item>
          <el-form-item label="排序权重" prop="sortNum">
              <el-input-number 
                v-model="form.sortNum" 
                controls-position="right" 
                placeholder="请输入"
                :min="0" 
                style="width: 100%;"
                :disabled="viewsOptionState"
              >
              </el-input-number>
          </el-form-item>
          <el-form-item 
          label="关联贷超配置" prop="skillConfigId"
          v-if="![2].includes(form.pickType)"
          >
            <el-select
              v-model="form.skillConfigId"
              clearable
              filterable
              placeholder="请选择"
              style="width: 100%"
              :disabled="viewsOptionState"
              @change="changeSkillConfigId"
            >
              <el-option
                v-for="(item, index) in skillConfigIdOption"
                :key="index"
                :label="item.configName"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item 
           label="渠道号" prop="deptCode"
           v-if="[0,1].includes(form.pickType)"
          >
             <el-input
               v-model="form.deptCode"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>
          <el-form-item 
          label="撞库方法" prop="checkClass"
          v-if="[1].includes(form.pickType)"
          >
             <el-input
               v-model="form.checkClass"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>
          <el-form-item 
          label="撞库地址" prop="checkUrl"
           v-if="[1].includes(form.pickType)"
          >
             <el-input
               v-model="form.checkUrl"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>
          <el-form-item label="注册方法" prop="pushClass"
           v-if="[0,1].includes(form.pickType)"
          >
             <el-input
               v-model="form.pushClass"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>
          <el-form-item label="注册地址" prop="pushUrl"
           v-if="[0,1].includes(form.pickType)"
          >
             <el-input
               v-model="form.pushUrl"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>
          <el-form-item 
            label="AesKey" 
            prop="outAesKey"
            v-if="[0,1].includes(form.pickType)"
          >
             <el-input
               v-model="form.outAesKey"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>
          <el-form-item 
            label="AesIv" 
            prop="outAesIv"
            v-if="[0,1].includes(form.pickType)"
          >
             <el-input
               v-model="form.outAesIv"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>
          <el-form-item 
            label="外部私钥" 
            prop="outPrivateKey"
            v-if="[0,1].includes(form.pickType)"
          >
             <el-input
               v-model="form.outPrivateKey"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>
          <el-form-item 
            label="外部公钥" 
            prop="outPublicKey"
            v-if="[0,1].includes(form.pickType)"
          >
             <el-input
               v-model="form.outPublicKey"
               style="width: 100%"
               placeholder="请输入"
               clearable
               disabled
             />
          </el-form-item>

         
        </el-form>
        <div slot="footer" class="dialog-footer" v-if="!viewsOptionState">
          <el-button type="primary" @click="handleSubmit('formRef')"
            >确 定</el-button
          >
          <el-button @click="handleClose">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import tableStickyMixins from "@/mixins/tableStickyMixins";
  import { mapGetters } from "vuex";
  import { getUpChannelList } from "@/api/business/channelManagement";
  import { querySysUserManageList } from "@/api/system/userManage";
  import {getDwnCompanyList} from "@/api/business/downCompanyManagement";
  import{
    addOrEdit,
    deleteById,
    getAdvertType,
    getFeeType,
    onOrOff,
    queryById,
    queryAdvertByPage,
    queryProductList,
    getPickUrlById
  } from "@/api/business/downdAvertManagement"
  import {queryProductList as pickQueryProductList} from "@/api/business/upPickManagement";
  import {queryDownPickUrlConfigList} from "@/api/globalConfig/downPickUrl";
  import {getAreaCodeTreeList} from '@/api/system/areaCode'
  import moment from "moment";

  export default {
    // 定义名字用于标识该组件是否被keep-alive缓存
    name: "DowndAvertManagement",
    data() {
      return {
        // 贷超管理列表
        dataList: [],
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          pageIndex: 1,
          pageSize: 10,
        },
        // 查询时间范围
        dateRange: [],
        // 采量时间范围
        pickDateRange:null,
        loading: false,
        // 显示搜索栏
        showSearch: true,
        // 弹框标题
        title: "",
        // 弹框显示状态
        dialogShow: false,
        // 弹框的表单信息
        form: {
          // 默认状态在线
          status:0
        },
        // 弹框表单校验规则
        rules: {
          productUrl:[
            { required: true, message: "请输入跳转链接", trigger: "change" }
          ]
        },
        // 上游公司筛选项列表
        downCompanyList: [],
        // 渠道限制筛选项
        isChannelOption:[
          { label: "无限制", value: 0 },
          { label: "排除渠道", value: 1 },
          { label: "包含渠道", value: 2 },
        ],
        // 限制渠道集合筛选项
        channelIdsOption:[],
        // 城市限制筛选项
        isCityOption:[
          { label: "否", value: 0 },
          { label: "排除", value: 1 },
          { label: "包含", value: 2 },
        ],
        // 企微产品筛选项
        isWeChatOption:[
          { label: "否", value: 0 },
          { label: "是", value: 1 },
        ],
        // 增加时间类型
        isZoneOption:[
          { label: "白天", value: 0 },
          { label: "夜间", value: 1 },
        ],
        // 状态筛选项
        statusOption: [
          { label: "在线", value: 0 },
          { label: "下线", value: 1 },
          { label: "停用", value: 2 },
        ],
        // 渠道产品筛选项列表
        upChannelList:[],
        // 管理人筛选项列表
        manageOptionList: [],
        // 计费模式筛选项
        feeTypeOption:[],
        // 贷超模式筛选项
        pickTypeOption:[],
        // 表格列信息（用于控制显示与隐藏)
        columnsList:[],
        //关联贷超配置筛选项
        skillConfigIdOption:[],


        // 临时状态变量
        tempStatus:null,
        // 当前激活项行数据
        rowIndex:null,
        // 上下线状态
        upAndDownLinesStates:null,

        // 全国省市区列表(树型结构)
        areaList: [],



      };
    },
    mixins: [tableStickyMixins],
    watch: {
      columns: {
        handler() {
          // 清空popover激活项索引
          this.rowIndex = null
          this.updateTableHeight();
        },
        deep: true,
      },
      dataList:{
      handler() {
        // 清空popover激活项索引
        this.rowIndex = null
      },
      deep: true,
    },
    },
    created() {
      this.init();
      this.getDownCompanyList()
      this.getChannelList()
      this.getManageList()
      this.getRelatedType()
      this.getSkillConfigIdOption()
      this.getChannelIdsList()
      this.getProvinceCityList()
    },
    computed: {
      ...mapGetters(["sidebar", "device"]),
      // 计算当前列元素在所处环境的宽度
      getColumnWidth() {
        return (index) => {
          return this.isMobile
            ? this.columns[index].mobileWidth
            : this?.sidebar?.opened
            ? this.columns[index].pcWidth - this.slightWidth
            : this.columns[index].pcWidth + 17;
        };
      },
  
      // (是否处于查看操作禁用表单项)
      viewsOptionState() {
        return this.title === "查看贷超";
      },
      // 对状态进行处理
      statusColor:()=>{
          return (state)=>{
             switch(state){
               case 0:
                  return 'success';
               case 1:
                  return 'info';
               case 2:
                  return 'danger';
               default:
             }
          }
       },
       // 将数组转换为对象形式
       ArrayFormatObj:()=>{
           return (arr)=>{
             return arr.reduce((pre, cur)=>{
               pre[cur.value] = cur.label;
               return pre;
             },{})
           }
        },
       // 表格列信息计算属性
       columns(){
         const arr = [
          {label: `ID`,prop: "id",visible: true,pcWidth: 150,mobileWidth: 100,fixed: this.device === 'mobile'? null: 'left',showTooltip: true,},
          {label: `上游公司名称`,prop: "companyName",visible: true,pcWidth: 130,mobileWidth: 110,fixed:this.device === 'mobile'? null: 'left',showTooltip: true,},
          {label: `产品简称`,prop: "simpleName",visible: true,pcWidth: 100,mobileWidth: 100,fixed: this.device === 'mobile'? null: 'left',showTooltip: true,},
          {label: `产品名称`,prop: "productName",visible: true,pcWidth: 120,mobileWidth: 100,fixed: this.device === 'mobile'? null: 'left',showTooltip: true,},
          {label: `产品logo`,prop: "logoUrl",visible: true,pcWidth: 120,mobileWidth: 110,fixed: null,showTooltip: true,},
          {label: `贷超模式`,prop: "pickTypeStr",visible: true,pcWidth: 155,mobileWidth: 155,fixed: null,showTooltip: true,},
          {label: `计费模式`,prop: "feeTypeStr",visible: true,pcWidth: 100,mobileWidth: 110,fixed: null,showTooltip: true,},
          {label: `单价`,prop: "priceMoney",visible: true,pcWidth: 100,mobileWidth: 110,fixed: null,showTooltip: false,sortable: true,},
          {label: `企微产品`,prop: "isWeChat",visible: true,pcWidth: 100,mobileWidth: 110,fixed: null,showTooltip: false,},

          {label: `开始时间`,prop: "startTime",visible: true,pcWidth: 100,mobileWidth: 100,fixed: null,showTooltip: true,sortable: true,},
          {label: `结束时间`,prop: "endTime",visible: true,pcWidth: 100,mobileWidth: 100,fixed: null,showTooltip: true,sortable: true,},
          {label: `轮转数`,prop: "plusNum",visible: true,pcWidth: 100,mobileWidth: 100,fixed: null,showTooltip: true,},

          {label: `在线状态`,prop: "status",visible: true,pcWidth: 120,mobileWidth: 100,fixed: null,showTooltip: true,},
          {label: `排序权重`,prop: "sortNum",visible: true,pcWidth: 100,mobileWidth: 110,fixed: null,showTooltip: false,sortable: true,},
          {label: `每日限量`,prop: "orderNum",visible: true,pcWidth: 120,mobileWidth: 100,fixed: null,showTooltip: true,sortable: true,},
          {label: `展示额度`,prop: "quota",visible: true,pcWidth: 120,mobileWidth: 100,fixed: null,showTooltip: true,sortable: true,},
          {label: `年化率`,prop: "yearRate",visible: true,pcWidth: 120,mobileWidth: 110,fixed: null,showTooltip: false,sortable: true,},
          {label: `贷款期限`,prop: "termNum",visible: true,pcWidth: 120,mobileWidth: 100,fixed: null,showTooltip: true,sortable: true,},
          {label: `创建时间`,prop: "createTime",visible: true,pcWidth: 180,mobileWidth: 100,fixed: null,showTooltip: true,sortable: true,},
          {label: `最后修改时间`,prop: "updateTime",visible: true,pcWidth: 180,mobileWidth: 100,fixed: null,showTooltip: true,sortable: true,},
          {label: `管理员`,prop: "manageUserName",visible: true,pcWidth: 160,mobileWidth: 100,fixed: null,showTooltip: true,},
          {label: `操作`,prop: "operation",visible: true,pcWidth: 100,mobileWidth: 80,fixed: "right",showTooltip: true,},
        ]
        this.$set(this,'columnsList',arr)
        return arr;
       }
    },
    methods: {
      cascaderChangeFun(){
        const cascader = this.$refs.cascaderRef;
        if (cascader) {
          if (cascader.handleClear) {
            cascader.handleClear(); // 清除 UI 上的输入和选中
          }
          // if (cascader.handleExpandChange) {
          //   cascader.handleExpandChange([]); // 重置展开路径，回到根节点
          // }
        }
        // 强制更新组件
        this.$forceUpdate();
      },
      // 获取全国省市区列表
      getProvinceCityList() {
        getAreaCodeTreeList().then((res) => {
          this.areaList = res?.data;
        });
      },
      // 获取限制渠道列表
      getChannelIdsList(){
        pickQueryProductList().then((res) => {
          this.channelIdsOption = res?.data;
        });
      },
      // 获取下游公司管理
      getDownCompanyList() {
        getDwnCompanyList().then((res) => {
           this.downCompanyList = res.data;
        });
      },
       // 获取渠道筛选项列表
       getChannelList(){
         // 获取上游渠道列表
         getUpChannelList().then((res) => {
           this.upChannelList = res.data;
         });
       },
       // 获取管理人列表
       getManageList() {
         querySysUserManageList().then((res) => {
           this.manageOptionList = res?.data;
         });
       },
        // 获取关联贷超配置列表
        getSkillConfigIdOption(){
          queryDownPickUrlConfigList().then(res=>{
            if(res.code == 200){
              this.skillConfigIdOption = res.data;
            }
          })
        },
       // 获取相关模式
       getRelatedType() {
          getFeeType().then((res) => {
            this.feeTypeOption = res?.data;
          });
          getAdvertType().then((res) => {
            this.pickTypeOption = res?.data;
          });
       },
       // 图片上传的回调
       fileUploadFunction(url){
          this.$set(this.form,'logoUrl',url)
       },
       // 显示上下线弹出窗回调
       showOrOffPopo(row) {
         // 设置上下线状态
         this.upAndDownLinesStates = row?.status
         // 设置索引打开弹窗
         this.rowIndex = row?.id
         // 设置临时变量
         this.tempStatus = row?.status;       
       },
       // 点击提交修改上下线状态
       clickSubmitOnOrOff(row) {
          const params = {
            id: row?.id,
            status:this.upAndDownLinesStates,
          };
          if(this.upAndDownLinesStates===this.tempStatus){
            return this.$message.error(`贷超已${this.ArrayFormatObj(this?.statusOption)[row?.status]},请勿重复操作！`);
          }
          onOrOff(params).then((res) => {
            if(res.code === 200){
              this.$message.success("操作成功");
              this.getList();
              this.rowIndex = null;
            }
          });
       },
       // 点击取消修改上下线状态
       clickCancelOnOrOff(row){
          row.status = this.tempStatus
          this.$message.info("取消操作");
          this.rowIndex = null;
       },

      /** 搜索按钮操作 */
      handleQuery() {
        this.$set(this.queryParams, "pageIndex", 1);
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        // 完全重置到初始状态
        this.$set(this, "queryParams", {
          pageIndex: 1,
          pageSize: 10,
        });
        // 重置时间范围
        this.$set(this, "dateRange", []);
        this.init();
      },
      init() {
        this.getList();
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        if (this.dateRange?.length) {
          this.queryParams.createTimeStart = this.dateRange[0];
          this.queryParams.createTimeEnd = this.dateRange[1];
        } else {
          delete this.queryParams.createTimeStart;
          delete this.queryParams.createTimeEnd;
        }
        queryAdvertByPage(this.queryParams).then((response) => {
          // 解决id为number类型精度丢失问题
          this.dataList = response?.data?.list.map((row) => {
            return {
              ...row,
              id: row.id.toString(),
            };
          });
          this.total = response?.data?.total;
          this.loading = false;
        }).catch((err) => {
          setTimeout(() => {// 延迟2s后自动取消加载状态
            this.loading = false;
          }, 2000);
        })
      },
      // 获取详情
      getUpPickDetail(id) {
        queryById(id).then((response) => {
          this.form = response.data;
          // 采量时间映射处理
          if (response.data.startTime && response.data.endTime) {
            const startTime = new Date();
            const endTime = new Date();
            startTime.setHours(...response.data.startTime.split(':').map(Number));
            endTime.setHours(...response.data.endTime.split(':').map(Number));

            // 设置 开始事件和结算时间
            this.$set(this.form, 'startTime', startTime);
            this.$set(this.form, 'endTime', endTime);
          }
          // 关联贷超配置回显设置
          this.changeSkillConfigId(response.data?.skillConfigId)
        });
      },
      // 关联贷超配置改变后的回调
      changeSkillConfigId(pickConfigId){
        let query = {
          id:this.form?.id,
          pickConfigId
        }
        getPickUrlById(query).then(res=>{
          this.$set(this,'form',{
            ...JSON.parse(JSON.stringify(this.form)),
            ...res?.data
          })
        })
      },
      // 修改表格高度触发回调
      updateTableHeight() {
        this.$nextTick(() => {
          this.$refs.table.doLayout();
        });
      },
      // 处理对话框
      handelDialog(title, row = null) {
        this.title = title + "贷超";
        switch (title) {
          case "查看":
            // 获取贷超详细信息回显数据
            this.getUpPickDetail(row?.id);
            break;
          case "添加":
            break;
          case "编辑":
            // 获取公司详细信息回显数据
            this.getUpPickDetail(row?.id);
            break;
          default:
          // 其他操作
        }
        this.dialogShow = true;
      },
      /*关闭弹窗*/
      handleClose() {
        this.$refs["formRef"].resetFields();
        this.form = this.$options.data().form;
        // 清空采量时间
        this.$set(this,'pickDateRange',null)
        this.dialogShow = false;
      },
      // 取消删除
      hanCancelDel() {
        this.$message({
          type: "info",
          message: "已取消删除操作",
        });
      },
      // 删除列表项
      handelDel(row) {
        deleteById(row?.id).then((res) => {
          if (res.code === 200) {
            this.$message.success("删除成功");
            this.getList();
          }
        });
      },
      // 刷新数据且关闭弹框
      handleRefresh() {
        // 刷新数据
        this.getList();
        // 关闭弹窗
        this.handleClose();
      },
      /*提交操作*/
      handleSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let params = {};
            params = JSON.parse(JSON.stringify(this.form));
            if(!this?.form?.startTime){
              return this.$message.error("请选择开始时间");
            }
            if(!this?.form?.endTime){
              return this.$message.error("请选择结束时间");
            }
            // 采量时间范围处理
            params.startTime = moment(this?.form?.startTime).format("HH:mm");
            params.endTime = moment(this?.form?.endTime).format("HH:mm");
            // 判断当前所处操作
            switch (this.title) {
              case "添加贷超":
                // 添加操作
                console.log("添加", params);
                addOrEdit(params).then((res) => {
                  if (res.code === 200) {
                    this.$message.success("添加成功");
                    this.handleRefresh();
                  }
                });
                break;
              case "编辑贷超":
                // 编辑操作
                console.log("编辑", params);
                addOrEdit(params).then((res) => {
                  if (res.code === 200) {
                    this.$message.success("编辑成功");
                    this.handleRefresh();
                  }
                });
                break;
              default:
              // 其他操作
            }
          }
        });
      },
    },
  };
  </script>
  
  <style scoped lang="scss">
  .title {
    font-size: 20px;
    color: #333333;
    font-weight: 500;
  }
  .search-box {
    margin: 0 0 20px;
    padding: 20px 20px 0;
    background: #fff;
    align-items: flex-start;
    border-radius: 6px;
  }
  .search-area {
    position: absolute;
    right: 20px;
  }
  .el-form-item__content {
    flex: 1;
    line-height: 40px;
    position: relative;
    font-size: 14px;
    min-width: 0;
  }
  ::v-deep .el-dialog__body {
    border-top: 1px solid #dfe6ec;
    border-bottom: 1px solid #dfe6ec;
  }
  .el-table {
    // 滚动条加粗
    --scrollbar-height: 9px;
  }
  </style>
  